package com.gxuwz.eschool;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.gxuwz.eschool.fragment.HomeFragment;
//收银台
public class CashierActivity extends AppCompatActivity {

    private ImageView iv_back;
    private Button btn_pay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cashier);
//        // 获取传递过来的金额
//        int selectedAmout = getIntent().getIntExtra("selected_amount",0);
//        // 显示金额
//        TextView tv_recharge_money = findViewById(R.id.tv_recharge_money);
//        tv_recharge_money.setText(String.valueOf(selectedAmout));

        iv_back = findViewById(R.id.iv_back);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentManager fragmentManager = getSupportFragmentManager();
                // 检查是否有Fragment可以回退
                if (fragmentManager.getBackStackEntryCount() > 0) {
                    fragmentManager.popBackStack(); // 返回上一个Fragment
                } else {
                    // 如果没有Fragment可以回退，可以结束当前Activity
                    finish();
                }
            }
        });
        btn_pay = findViewById(R.id.btn_pay);
        btn_pay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Toast.makeText(CashierActivity.this, "支付成功！", Toast.LENGTH_SHORT).show();
//                Intent intent = new Intent(CashierActivity.this, CardRechargeActivity.class);
//                startActivity(intent);
                new AlertDialog.Builder(CashierActivity.this)
                        .setTitle("提示")
                        .setMessage("支付成功！")
                        .setPositiveButton("完成", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // 在这里执行页面跳转的操作
                                Intent intent = new Intent(CashierActivity.this, MainActivity.class);
                                startActivity(intent);
                                finish(); // 在跳转后关闭当前Activity
                            }
                        })
                        .show();

            }
        });
    }
}